package com.cd826dong.clouddemo.api;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import rx.Observable;
import rx.observables.BlockingObservable;

import com.cd826dong.clouddemo.service.HystrixCommandFailureService;
import com.cd826dong.clouddemo.service.HystrixObservableCommandFailureService;

@RestController()
@RequestMapping("/hystrixObservableCommandApi")
public class HystrixObservableCommandApi {

	@Autowired
	@Qualifier(value = "restTemplate")
	private RestTemplate restTemplate;
	
	@RequestMapping(value = "/test")
	public String testName() throws InterruptedException, ExecutionException  {
		Observable<String> observable = new HystrixObservableCommandFailureService(restTemplate, "hystrixObservableCommandTest").toObservable();
		BlockingObservable<String> blockingObservable = observable.toBlocking();
		Future<String> future = blockingObservable.toFuture();
		return future.get();
	}
}
